<?php

!defined('IN_APP') && exit('Access Denied');

class customercontrol extends base {

    function __construct(& $get, & $post) {
        parent::__construct($get, $post);
        $this->load("customer");
        $this->load("area");
        $this->load("user");
    }

    /* 今日客户列表 */

    function ondaily() {
        $todaystart = strtotime(date("Y-m-d 00:00:00"));
        $todayend = strtotime(date("Y-m-d 23:59:59"));
        $customerlist = $_ENV['customer']->get_by_time($todaystart, $todayend);
        include template('dailycustomer');
    }

    /* 添加客户 */

    function onadd() {
        if (isset($this->post['submit'])) {
            $cid = $_ENV['customer']->add($this->post['cusername'], $this->post['cgender'], $this->post['mobile'], $this->post['email'], $this->post['phone'], $this->post['fax'], $this->post['address'], $this->post['postcode'], $this->post['state'], $this->post['country'], $this->post['passporttype'], $this->post['inviteletter'], $this->post['peoplenum'], $this->post['urgent'], $this->post['interview'], $this->post['price'], $this->post['sourcetype'], $this->post['status'], $this->post['signedstate']);
            $_ENV['customer']->addpassport($cid, $this->post['passportnum'], strtotime($this->post['passportstart']), strtotime($this->post['passportend']), $this->post['pusername'], $this->post['pgender'], $this->post['homecity'], $this->post['passportcity'], strtotime($this->post['departuretime']), $this->post['pcomment']);
            $_ENV['customer']->addpayment($cid, $this->post['price'], $this->post['price'], $this->post['passportexpense'], $this->post['payobject'], $this->post['insuranceexpense'], $this->post['invoice'], $this->post['invoicemoney'], $this->post['money'], $this->post['paytype'], $this->post['finalpay'], $this->post['finalpaystatus'], $this->post['confirmor']);
        }
        $statelist = $_ENV['area']->get_by_pid(0);
        $citylist = $_ENV['area']->get_by_pid(6);
        include template("addcustomer");
    }

    /* 修改信息 */

    function onedit() {
        $cid = $this->post['cid'] ? $this->post['cid'] : $this->get['cid'];
        if (isset($this->post['submit'])) {
            $_ENV['customer']->update($cid, $this->post['cusername'], $this->post['cgender'], $this->post['mobile'], $this->post['email'], $this->post['phone'], $this->post['fax'], $this->post['address'], $this->post['postcode'], $this->post['state'], $this->post['country'], $this->post['passporttype'], $this->post['inviteletter'], $this->post['peoplenum'], $this->post['urgent'], $this->post['interview'], $this->post['price'], $this->post['sourcetype'], $this->post['status'], $this->post['signedstate']);
            $_ENV['customer']->updatepassport($cid, $this->post['passportnum'], strtotime($this->post['passportstart']), strtotime($this->post['passportend']), $this->post['pusername'], $this->post['pgender'], $this->post['homecity'], $this->post['passportcity'], strtotime($this->post['departuretime']), $this->post['pcomment']);
            $_ENV['customer']->updatepayment($cid, $this->post['price'], $this->post['price'], $this->post['passportexpense'], $this->post['payobject'], $this->post['insuranceexpense'], $this->post['invoice'], $this->post['invoicemoney'], $this->post['money'], $this->post['paytype'], $this->post['finalpay'], $this->post['finalpaystatus'], $this->post['confirmor']);
        }
        $customer = $_ENV['customer']->get($cid);
        $operator = $_ENV['user']->get_by_username($customer['operator']);
        $passport = $_ENV['customer']->getpassport($cid);
        $payment = $_ENV['customer']->getpayment($cid);
        $statelist = $_ENV['area']->get_by_pid(0);
        $citylist = $_ENV['area']->get_by_pid(6);
        $peoplerandom = range(1, 20);
        include template("editcustomer");
    }

    /* 根据状态读取客户信息 */

    function onstatus() {
        $customerlist = $_ENV['customer']->get_by_status($this->get['st']);
        include template("customerlist");
    }

    function onsearch() {
        $susername = $this->post['susername'] ? $this->post['susername'] : $this->get['susername'];
        $smobile = $this->post['smobile'] ? $this->post['smobile'] : $this->get['smobile'];
        $customerlist = $_ENV['customer']->search($susername, $smobile);
        include template("customerlist");
    }

}

?>